import styles from './index.less';
import Logapi from '../api/log.api'
import HTTP from '../services/api';
import SelfTable from '../tools/selfTable'
import { Table, message, notification,Tooltip,Button  } from 'antd'
import React from 'react';
import { isJSDocThisTag } from 'typescript';


export default class Grug extends React.Component {
    constructor() {
        super()
        this.state = {
            durginfo: [],
            columns:[]
        }
    }
    selfRender = text =>  <span style={{display:'block',textOverflow:'ellipsis',overflow:'hidden',wordBreak:'keep-all',whiteSpace:'nowrap'}}><Tooltip title={text}>{text}</Tooltip></span>

    getAllDrugInfo = async () => {
        let result = await HTTP({ method: 'get' }, Logapi.GetAllLogs)
       try{
        if (result && result.status) {
            // message.info(result.msg)
            notification.success({
                message: result.msg,
                description:`获取到日志有${result.info.length}条`,
                onClick: () => {
                    console.log('Notification Clicked!')
                }
            }
            )
            this.setState({ durginfo: result.info })
        }
        else {
            message.error(result.msg)
        }
       } catch(err){
        message.error('服务器异常')

       }
        console.log(result)

    }
    componentDidMount() {
        this.getAllDrugInfo()
    }
    render() {
        const columns = [
            ...this.state.columns,
            {
                title: '工作人员的id',
                dataIndex: 'work_id',
            },
            {
                title: '学生的id',
                dataIndex: 'student_id',
            },
            {
                title: '状态',
                dataIndex: 'status',
            },
            {
                title: '具体内容',
                dataIndex: 'content',
                render:text=><span style={{display:'block',textOverflow:'ellipsis',overflow:'hidden',wordBreak:'keep-all',whiteSpace:'nowrap'}}><Tooltip title={text}>{text}</Tooltip></span>
            },
            {
                title: '创建时间',
                dataIndex: 'createdAt',
                render:text =>this.selfRender(text)
            },
            {
                title: '更新时间',
                dataIndex: 'updatedAt'
            }
        ];
        columns.forEach((item,index)=>{
            console.log(item)
            console.log(index)
            let _self = this
            columns[index]['render'] = function a(text){
                _self.selfRender(text)
            }()
            columns[index]['align'] = 'center'

        })
        console.log(columns)
        console.log('-----------------')
        let { durginfo } = this.state
        return (
            <div>
                <SelfTable isshowHeader keyid='log_id' msg='工作人员查看日志记录'  dataSource={durginfo} columns={columns}  />
            </div>
        );
    }

}




